package yqt.com.cnki.service.impl;

import haha.life.common.CutPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yqt.com.cnki.bo.KYDABo;
import yqt.com.cnki.dao.IKYDADao;
import yqt.com.cnki.po.KYDAPo;
import yqt.com.cnki.po.KeyValuePo;
import yqt.com.cnki.service.IKYDAService;

import java.util.List;

/**
 * Description:
 *
 * @author BaiGe
 * @date: 2021/11/19 16:54
 * @Version 1.0
 */
@Service
public class KYDAServiceImpl implements IKYDAService {
    @Autowired
    private IKYDADao kydaDao;

    @Override
    public List<KeyValuePo> getKYDASort() {
        return kydaDao.getKYDASort();
    }

    @Override
    public List<KYDAPo> getKYDABySort_Index(String sortCode) {
        return kydaDao.getKYDABySort_LimitFive(sortCode);
    }

    @Override
    public KYDAPo getKYDAById(String sysId) {
        return kydaDao.getKYDAById(sysId);
    }

    @Override
    public CutPageBean<KYDAPo> complexSearch_kyda(KYDABo kydaBo) {
        String[] sortArr = kydaBo.getSortArr();
        StringBuffer sortArrStr = new StringBuffer();
        if (sortArr != null && sortArr.length > 0) {
            for (int i = 0; i < sortArr.length; i++) {
                sortArrStr.append("分类 = ").append(sortArr[i]).append(" or ");
            }
            if (sortArrStr.length() > 3) {
                String ortArrStr = sortArrStr.substring(0, sortArrStr.length() - 3);
                kydaBo.setSortArrStr(ortArrStr);
            }
        }

        kydaBo.setStart(kydaBo.getPage(), kydaBo.getPageSize());
        CutPageBean<KYDAPo> cutPageBean=new CutPageBean<>();
        List<KYDAPo> list = kydaDao.complexSearch_list(kydaBo);
        int count=(int)kydaDao.complexSearch_Count(kydaBo);
        cutPageBean.initCutPage(count, kydaBo.getPageSize(), list);
        return cutPageBean;
    }
}
